package net.osweb.core.tools.utils;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import javax.imageio.ImageIO;

import net.osweb.core.tools.exception.FileUploadException;

import org.apache.commons.io.FileUtils;

import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

/**
 * @author hgg
 * 图片处理类
 */
public class ImageUtil {
	
    @SuppressWarnings("unused")
	private static final float LOW_QUALITY=0.25F;
    @SuppressWarnings("unused")
	private static final float MEDIUM_QUALITY=0.75F;
	@SuppressWarnings("unused")
	private static final float HIGH_QUALITY=1.0F;
	@SuppressWarnings("unused")
	private static final float DEFALUT_QUALITY = 0.5F; 
	
	public static final String CENTER = "C"; 
	public static final String BOTTOM_LEFT = "L"; 
	public static final String BOTTOM_RIGTH = "R"; 
	private static final int WIDTH170 = 170;
	private static final int WIDTH50 = 50;
	private static final int WIDTH30 = 30;
	private static final int WIDTH100 = 100;
	private static final int WIDTH360 = 360;
	private static final int WIDTH966 = 966;
	@SuppressWarnings("unused")
	private static final int WIDTH1024 = 1024;
	
	private static final String _FONTNAME = null;
	private static final int _FONTSTYLE = 0;
	private static final int _COLOR = 0;
	
	
	private ImageUtil() {
	}

	
    /**
     * 加载图片
     * @param srcImg
     * @return
     */
    public static Image toImage(String src) {
        Image img = null;
        /*
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        img = toolkit.getImage(srcImg);        
        */
        try {
        	File srcFile = new File(src);
			img = ImageIO.read(srcFile);
		} catch (IOException e) {
			throw new FileUploadException(e);
		}
        
        return img;
    }	
    /**
     * 加载图片
     * @param srcImg
     * @return
     */
    public static Image toImage(File srcFile) {
    	Image img = null;
    	try {
    		img = ImageIO.read(srcFile);
    	} catch (IOException e) {
    		throw new FileUploadException(e);
    	}
    	
    	return img;
    }		
    /**
     * 加载图片
     * @param srcImg
     * @return
     */
    public static Image toImage(InputStream in) {
        Image img = null;
        try {
			img = ImageIO.read(in);
		} catch (IOException e) {
			throw new FileUploadException(e);
		}
        
        return img;
    }		
    private static void render(int width, int height, Image srcImg,String target,float quality) {
    	FileOutputStream out = null;
		try {
			BufferedImage bimg = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
			
			Graphics g = bimg.createGraphics();
			g.drawImage(srcImg, 0, 0, width, height, null);
			out = new FileOutputStream(target); 
			JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
			JPEGEncodeParam jep = JPEGCodec.getDefaultJPEGEncodeParam(bimg);
			if(quality != 0)
				jep.setQuality(quality, true); 
			encoder.encode(bimg, jep);
		} catch (ImageFormatException e) {
			throw new FileUploadException(e);
		} catch (IOException e) {
			throw new FileUploadException(e);
		}finally{
			try {
				if(out != null)
				out.close();
			} catch (IOException e) {
				throw new FileUploadException(e);
			}
		}        
    }
    /**
     * 不会生成图片，由内存写到另一个内存
     * @param width
     * @param height
     * @param srcImg
     * @param target
     * @param quality
     */
    private static void render2(int width, int height, Image srcImg ,OutputStream target,float quality) {
		try {
			BufferedImage bimg = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
			
			Graphics g = bimg.createGraphics();
			g.drawImage(srcImg, 0, 0, width, height, null);
			
			JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(target);
			JPEGEncodeParam jep = JPEGCodec.getDefaultJPEGEncodeParam(bimg);
			if(quality != 0)
				jep.setQuality(quality, true); 
			
			encoder.encode(bimg, jep);
		} catch (ImageFormatException e) {
			throw new FileUploadException(e);
		} catch (IOException e) {
			throw new FileUploadException(e);
		}finally{
		}        
    }   
    
	/**
	 * 判断文件路径是否正确
	 * @param src
	 */
	private static File checkForNull(String src)
	{
		return checkForNull(src,"Cannot specify null for input files.");
	}	
	private static File checkForNull(String src,String message)
	{
		if (src == null) {
			throw new FileUploadException(message);
		}	
		File f = new File(src);
		if (!f.exists())
		{
			throw new FileUploadException(message);
		}
		return f;
	}		
	/**
	 * 调整大小：100*auto
	 * @param srcImg
	 * @param targetImg
	 * @return
	 */
	public static String resize100(String src,String target){
		File srcFile = checkForNull(src);
		Image srcImg = toImage(srcFile);
		if(srcImg.getWidth(null) < WIDTH100)
			return src;
		return resize(WIDTH100, srcImg, target);
	}

    /**
     * 调整大小：360*auto
     * @param srcImg
     * @param targetImg
     * @return
     */
    public static String resize360(String src,String target){    	
    	File srcFile = checkForNull(src);
    	Image srcImg = toImage(srcFile);
    	if(srcImg.getWidth(null) < WIDTH360)
    		return src;    	
    	return resize(WIDTH360, srcImg, target);
    }
 
    /**
     * 调整大小：966*auto
     * @param srcImg
     * @param targetImg
     * @return
     */
    public static String resize966(String src,String target){    	
    	File srcFile = checkForNull(src);
    	Image srcImg = toImage(srcFile);
    	if(srcImg.getWidth(null) < WIDTH966)
    		return src;  
    	return resize(WIDTH966, srcImg, target);
    }
    
    public static String resize(int _width,Image srcImg,String target){  
    	int width = srcImg.getWidth(null); 
    	int height = srcImg.getHeight(null);  	
    	
    	float s = getRatio(width, _width);
    	int h = (int) (height * s);	
    	
    	render(_width, h, srcImg, target, 0);
    	
    	return target;
    }    
    
    
    
    
    
    /**
     * 调整大小：170*auto
     * @param srcImg
     * @param targetImg
     * @return
     */
    public static void resize170(InputStream in,OutputStream target){
    	Image srcImg = toImage(in);
    	if(srcImg.getWidth(null) < WIDTH170){
    		
    		return;
    	}
    	resize(WIDTH170, srcImg, target);
    }
    
   
    
    /**
     * 调整大小：170*auto
     * @param srcImg
     * @param targetImg
     * @return
     */
    public static void resize30(InputStream in,OutputStream target){
    	Image srcImg = toImage(in);
    	if(srcImg.getWidth(null) < WIDTH30){
    		
    		return;
    	}
    	resize(WIDTH30, srcImg, target);
    }
    
    
    /**
     * 调整大小：50*auto
     * @param srcImg
     * @param targetImg
     * @return
     */
    public static void resize50(InputStream in,OutputStream target){
    	Image srcImg = toImage(in);
    	if(srcImg.getWidth(null) < WIDTH50){
    		
    		return;
    	}
    	resize(WIDTH50, srcImg, target);
    }
    /**
     * 调整大小：100*auto
     * @param srcImg
     * @param targetImg
     * @return
     */
    public static void resize100(InputStream in,OutputStream target){
    	Image srcImg = toImage(in);
    	if(srcImg.getWidth(null) < WIDTH100){
    		
    		return;
    	}
    	resize(WIDTH100, srcImg, target);
    }    
    /**
     * 调整大小：360*auto
     * @param srcImg
     * @param targetImg
     * @return
     */
    public static void resize360(InputStream in,OutputStream target){    	
    	Image srcImg = toImage(in);
    	if(srcImg.getWidth(null) < WIDTH360)
    		return;    	
    	resize(WIDTH360, srcImg, target);
    }    
    /**
     * 调整大小：966*auto
     * @param srcImg
     * @param targetImg
     * @return
     */
    public static void resize966(InputStream in,OutputStream target){    	
    	Image srcImg = toImage(in);
    	if(srcImg.getWidth(null) < WIDTH966)
    		return;  
    	resize(WIDTH966, srcImg, target);
    }    
    
    /**
     * 调整大小：_width*auto
     * @param srcImg
     * @param targetImg
     * @return
     */
    public static void resize(int _width,InputStream in,OutputStream target){    	
    	Image srcImg = toImage(in);
    	if(srcImg.getWidth(null) < _width)
    		return;  
    	resize(_width, srcImg, target);
    } 
    
    public static void resize(int _width,Image srcImg,OutputStream out){  
    	int width = srcImg.getWidth(null); 
    	int height = srcImg.getHeight(null);  	
    	
    	float s = getRatio(width, _width);
    	int h = (int) (height * s);	
    	
    	render2(_width, h, srcImg, out, 0);
    }    
    
    
    /**
     * 图片压缩<br>
     * 不改变大小<br>
     * @param src
     * @param target
     * @return
     */
    public static void compress(String src,String target){
    	//1?动画图片需要压缩不
    	//2?多大容积的图片就不要压缩了
    	//3？
    	File srcFile = checkForNull(src);
    	Image srcImg = toImage(srcFile);
    	int width = srcImg.getWidth(null); 
    	int height = srcImg.getHeight(null);  	
    	float quality =getScaleSpace(srcFile.length(),width,height);
    	
    	render(width, height, srcImg, target, quality);	
    }
    /**
     * 图片压缩<br>
     * 不改变大小<br>
     * @param src
     * @param target
     * @return
     */
    public static void compress(InputStream in,OutputStream out,int len){
    	Image srcImg = toImage(in);
    	int width = srcImg.getWidth(null); 
    	int height = srcImg.getHeight(null);  	
    	float quality =getScaleSpace(len,width,height);
    	
    	render2(width, height, srcImg, out, quality);	
    }
    
    
    
    
    /**
     * @param pressText 水印文字
     * @param srcImg   源文件
     * @param targetImg  结果文件
     * @param type   水印位置
     */
    public static void watermarkText(String pressText, String srcImg,String targetImg,String type){
    	pressText(pressText, srcImg, targetImg, type);
//    	pressText(pressText, srcImg, targetImg, fontName, fontStyle, color, fontSize, x, y, type);
    }
    public static String watermarkImg(){return null;}
    
    
    
	/**
	 * 压缩图片<br>
	 * 默认比例：width:966 height:auto<br>
	 * @param srcImg
	 * @param targetImg
	 * @return
	 */
	public static String zip(String srcImg,String targetImg){
		if (srcImg == null) {
			return null;
		}
		return zip(new File(srcImg),targetImg,WIDTH966);
	}
	/**
	 * 压缩图片
	 * @param srcImg
	 * @param width
	 * @param height
	 * @param quality
	 * @param targetImg
	 * @return
	 */
	public static String zip(String srcImg, int width, int height,
			float quality, String targetImg,int _w){
		if(width==0 && height==0 && quality ==0)
			return zip(srcImg,targetImg);
		
		if (srcImg == null) {
			return null;
		}
		
		return zip(new File(srcImg), width, height,quality, targetImg,_w);
	}
	/**
	 * 压缩图片<br>
	 * 压缩占用空间<br>
	 * 压缩长宽：width:966 height:auto<br>
	 * 如果width<966,只压缩图片占用空间
	 * @param srcImg
	 * @param targetImg
	 * @return
	 */
	public static String zip(File srcImg,String targetImg,int w){
		if (srcImg == null) {
			return null;
		}
		FileOutputStream out = null;
		int width = -1;
	    int height = -1;
		try {
			
			//对临时文件进行处理
			Image srcFile = ImageIO.read(srcImg);  
			width = srcFile.getWidth(null); // 得到源图宽
            height = srcFile.getHeight(null); // 得到源图长
            
			float quality =getScaleSpace(srcImg.length(),width,height);
            
            float s = getRatio(width,w);
	        int h = (int) (height * s);
	        
			BufferedImage tag = new BufferedImage(w, h,BufferedImage.TYPE_INT_RGB);
			tag.getGraphics().drawImage(srcFile, 0, 0, w, h, null);
			out = new FileOutputStream(targetImg); //压缩后的新图
			JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
			JPEGEncodeParam jep = JPEGCodec.getDefaultJPEGEncodeParam(tag);
			jep.setQuality(quality, true); //压缩质量
			encoder.encode(tag, jep);

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			try {
				if(out != null)
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return targetImg;
	}	
	/**
	 * 压缩图片
	 * @param srcImg
	 * @param width
	 * @param height
	 * @param quality
	 * @param targetImg
	 * @return
	 */
	public static String zip(File srcImg, int width, int height,
			float quality, String targetImg,int _w){
		FileOutputStream out = null;
		if(width==0 && height==0 && quality ==0)
			return zip(srcImg,targetImg,_w);
		
		if (srcImg == null) {
			return null;
		}
		try {
			Image srcFile = ImageIO.read(srcImg);
			BufferedImage tag = new BufferedImage(width, height,
					BufferedImage.TYPE_INT_RGB);
			tag.getGraphics().drawImage(srcFile, 0, 0, width, height, null);
			out = new FileOutputStream(targetImg);
			JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
			JPEGEncodeParam jep = JPEGCodec.getDefaultJPEGEncodeParam(tag);
			jep.setQuality(quality, true);
			encoder.encode(tag, jep);

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			try {
				if(out != null)
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return targetImg;	
	}	
	
	public void cutout(){}
	public void press(){}
	
	/**
	 * 复制文件<br>
	 * 文件存放位置、上传的文件、文件名称<br>
	 * @param directory
	 * @param src
	 * @param fileName
	 * @return 上传后的文件名
	 */
	public static String copyFile(String directory,File src,String fileName){
		if(directory==null || "".equals(directory))
			return null;
		try {
			String suffix = getFileSuffix(fileName);
			String targetName = makeFileName(suffix);
			File target = new File(directory, targetName);
			FileUtils.copyFile(src, target);
			
			return target.getAbsolutePath();
		} catch (IOException e) {
			e.printStackTrace();
		} 
		return null;
	}
	
	/**
	 * 把图片印刷到图片上
	 * @param pressImg 水印文件
	 * @param targetImg 目标文件
	 * @param x
	 * @param y
	 */
	public final static void pressImage(String pressImg,String srcImg, String targetImg,int x, int y) {
		FileOutputStream out = null;
		
		if (srcImg == null) {
			return;
		}		
		
       try {
            File _file = new File(srcImg);
            Image src = ImageIO.read(_file);
            int width = src.getWidth(null);
            int height = src.getHeight(null);
            BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
            		
            Graphics g = image.createGraphics();
            g.drawImage(src, 0, 0, width, height, null);

            // 水印文件
            File _filewatermark = new File(pressImg);
            Image watermarkSrc = ImageIO.read(_filewatermark);
            int watermarkW = watermarkSrc.getWidth(null);
            int watermarkH = watermarkSrc.getHeight(null);
            g.drawImage(watermarkSrc, width - watermarkW - x, 
            		height - watermarkH -y, watermarkW,
            		watermarkH, null);
            g.dispose();
            out = new FileOutputStream(targetImg);
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
            encoder.encode(image);
            
        } catch (Exception e) {
            e.printStackTrace();
        }finally {   
    	   try {
	            if (out != null )   
	            	out.close();         
			} catch (Exception e) {
				e.printStackTrace();
			}
       }  
	}
	
	/**
	 * 文字添加水印
	 * @param pressText
	 * @param srcImg
	 * @param targetImg
	 * @param type
	 */
	public static void pressText(String pressText, String srcImg,String targetImg,String type) {
		
		pressText(pressText,srcImg,targetImg,_FONTNAME, _FONTSTYLE,_COLOR, 0,0,0,type);
				
	}
	
	
	/**
	 * 把文字印刷到图片上
	 * 
	 * @param pressText 文字
	 * @param targetImg  目标图片
	 * @param fontName 字体名
	 * @param fontStyle 字体样式
	 * @param color 字体颜色
	 * @param fontSize 字体大小
	 * @param x 偏移量
	 * @param y
	 */
	public static void pressText(String pressText, String srcImg,String targetImg,
			String fontName, int fontStyle, int color, int fontSize, int x,int y,String type) {
		FileOutputStream out = null;
		
		if (srcImg == null) {
			return;
		}		
		
        try {
            File _file = new File(srcImg);
            Image src = ImageIO.read(_file);
            int width = src.getWidth(null);
            int height = src.getHeight(null);
            BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
            Graphics g = image.createGraphics();
            g.drawImage(src, 0, 0, width, height, null);
            g.setColor(Color.WHITE);
            if(fontSize  == 0)
            	fontSize = getFontSize(width);
            g.setFont(new Font(fontName, fontStyle, fontSize));
            
            if(CENTER.equals(type)){
            	g.drawString(pressText, (width - (pressText.length() * fontSize)) / 2 + x, (height - fontSize) / 2 + y);
            }else if(BOTTOM_LEFT.equals(type)){
            	g.drawString(pressText, (width - (pressText.length() * fontSize)) / 2 + x, (height - fontSize) / 2 + y);
            }else{
            	g.drawString(pressText, (width - (pressText.length() * fontSize)) / 2 + x, (height - fontSize) / 2 + y);     	
            }
            g.dispose();
            out = new FileOutputStream(targetImg);
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
            encoder.encode(image);
        } catch (Exception e) {
           e.printStackTrace();
        }finally {   
     	   try {
	            if (out != null )   
	            	out.close();         
			} catch (Exception e) {
				e.printStackTrace();
			}
        }  		
	}	
	
	/**
	 * 添加水印文件，对流的处理
	 * @param pressText
	 * @param srcImg
	 * @param targetImg
	 * @param type
	 */
	public static void pressText2(String pressText, InputStream srcImg,OutputStream targetImg,String type) {
		pressText2(pressText,srcImg,targetImg,_FONTNAME, _FONTSTYLE,_COLOR, 0,0,0,type);
	}	
	public static void pressText2(String pressText, InputStream srcImg,OutputStream targetImg,
			String fontName, int fontStyle, int color, int fontSize, int x,int y,String type) {
		if (srcImg == null) {
			return;
		}		
        try {
            Image src = toImage(srcImg);
            
            int width = src.getWidth(null);
            int height = src.getHeight(null);
            BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
            Graphics g = image.createGraphics();
            g.drawImage(src, 0, 0, width, height, null);
            g.setColor(Color.WHITE);
            if(fontSize  == 0)
            	fontSize = getFontSize(width);
            g.setFont(new Font(fontName, fontStyle, fontSize));
            
            if(CENTER.equals(type)){
            	g.drawString(pressText, (width - (pressText.length() * fontSize)) / 2 + x, (height - fontSize) / 2 + y);
            }else if(BOTTOM_LEFT.equals(type)){
            	g.drawString(pressText, (width - (pressText.length() * fontSize)) / 2 + x, (height - fontSize) / 2 + y);
            }else{
            	g.drawString(pressText, (width - (pressText.length() * fontSize)) / 2 + x, (height - fontSize) / 2 + y);     	
            }
            g.dispose();
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(targetImg);
            encoder.encode(image);
        } catch (Exception e) {
           e.printStackTrace();
        }finally {
        	
        }		
	}	
	
	
	public static void rotate(String srcImg,String targetImg,int degree){
		if (srcImg == null) {
			return;
		}	
		File _file = new File(srcImg);
        Image src;
        FileOutputStream out = null;
		try {
			src = ImageIO.read(_file);
			int width = src.getWidth(null);
			int height = src.getHeight(null);
			
			BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
			
			Graphics2D g = image.createGraphics();
//			g.drawImage(src, 0, 0, width, height, null);	      
			g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
			
			g.rotate(Math.toRadians(degree), width / 2, height / 2);
			g.drawImage(src, 0, 0, null);
			g.dispose();	              
			
			out = new FileOutputStream(targetImg);
	        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
	        encoder.encode(image);		
			
			
		} catch (IOException e) {
			e.printStackTrace();
		}finally {   
     	   try {
	            if (out != null )   
	            	out.close();         
			} catch (Exception e) {
				e.printStackTrace();
			}
        } 
	}
	
	
	@SuppressWarnings("unused")
	private int getAutoWidth(int oldWidth){
		return 0;
	}
	
	/**
	 * 获取长度缩小比例
	 * @param oldWdith
	 * @param newWidth
	 * @return
	 */
	private static float getRatio(int oldWidth,int newWidth){
		if(oldWidth == 0 || oldWidth < newWidth)
			return 1F;
		float s = (float) newWidth / oldWidth;
		return s;
	}
	/**
	 * 获取图片占用空间压缩的比例
	 * @param fileSize
	 * @return
	 */
	private static float getScaleSpace(long fileSize,int width,int height){
		//FIXME: 处理压缩空间
		return 0.1F;
	}	
	/**
	 * 删除多个文件
	 * @param paths
	 */
	public static void deleteFiles(List<String> paths){
		for(String path : paths)
			deleteFile(path);
	}
	/**
	 * 删除单个文件
	 * @param path
	 * @return
	 */
	public static boolean deleteFile(String path){
		boolean flag = false;
		File f = new File(path);
		if(f.exists())
			flag = f.delete();
		else
			return true;
		return flag;
	}
	
	/**
	 * 重命名<br>
	 * 绝对路径\文件名.后缀<br>
	 * c:\123.jpg<br>
	 * @param path
	 * @param oldFileName
	 * @return
	 */
	public static String makeFileName(String path,String oldFileName){
		String suffix = getFileSuffix(oldFileName);
		return path + File.separator + makeFileName(suffix);
	}
	
	/**
	 * 重命名<br>
	 * 文件名.后缀<br>
	 * 123.jpg<br>
	 * @param prex
	 * @return
	 */
	public static String makeFileName(String prex){
		return UuidUtil.getUUID()+prex;
	}
	/**
	 * 重命名<br>
	 * 文件名<br>
	 * 123<br>
	 * @param prex
	 * @return
	 */
	public static String makeFileName(){
		return UuidUtil.getUUID();
	}
	public static String reFileName(String fileName,String prex){
		String suffix = getFileSuffix(fileName);
		if(suffix==null || "".equals(suffix))
			return null;
		if(!fileName.contains("."))
			return null;		
		return new String(fileName.substring(0, fileName.lastIndexOf('.')) + prex + suffix );
	}	
	
	/**
	 * 获取文件后缀
	 * @param fileName
	 * @return
	 */
	public static String getFileSuffix(String fileName){
		if(fileName ==null || "".equals(fileName))
			return null;
		if(!fileName.contains("."))
			return null;
		return new String(fileName.substring(fileName.lastIndexOf('.'), fileName.length()));
	}	
	
	/**
	 * 根据图片的大小设置水印字体大小
	 * @param width
	 * @return
	 */
	public static int getFontSize(int width){
		int default_width = 1024;
		int default_size = 25;
		
		float s = (float) width / default_width;
		
		return (int)(default_size * s);
	}

}

